*************************************************************
* Title: 3_pre_gss											*
* Authors: Peter Kuhn, Trevor Osaki, Lei Yue                *
* Purpose: To prepare GSS Data for tables	                *
* Date: September 2024                                      *
*************************************************************
version 16

clear

cd $homedir

* Access the 2020 GSS
use d4_gss2020.dta, replace

keep if panstat == 1

drop age_1a degree_1a sex_1a age_1b degree_1b sex_1b partyid_2 wtssall_2 wtss_2 

gen race_2 = 0
replace race_2 = race_1a if samptype == 2016
replace race_2 = race_1b if samptype == 2018

gen racecen1_2 = 0
replace racecen1_2 = racecen1_1a if samptype == 2016
replace racecen1_2 = racecen1_1b if samptype == 2018

gen racecen2_2 = 0
replace racecen2_2 = racecen2_1a if samptype == 2016
replace racecen2_2 = racecen2_1b if samptype == 2018

gen racecen3_2 = 0
replace racecen3_2 = racecen3_1a if samptype == 2016
replace racecen3_2 = racecen3_1b if samptype == 2018

gen male = (sex_2 == 1)
gen female = (sex_2 == 2)
gen age18_24 = (age_2 >= 18 & age_2 < 24)
gen age25_44 = (age_2 >= 25 & age_2 < 44)
gen age45_over = (age_2 >= 45)

gen race_white = (race_2 == 1)
gen race_non_white = (race_2 > 1)

gen education_hs_some_college = (degree_2 <= 2)
gen education_college_or_above = (degree_2 >= 3)

drop race_1a racecen1_1a racecen2_1a racecen3_1a race_1b racecen1_1b racecen2_1b racecen3_1b

* Drop non-responses
drop if degree > 5
drop if polviews > 7
drop if sex_2 > 2
drop if age_2 < 18

* Make dummies for political leaning
gen extremely_conservative = (polviews_2 == 7)
gen conservative = (polviews_2 == 6)
gen slightly_conservative = (polviews_2 == 5)
gen moderate = (polviews_2 == 4)
gen slightly_liberal = (polviews_2 == 3)
gen liberal = (polviews_2 == 2)
gen extremely_liberal = (polviews_2 == 1)

save "d6_gss2020_analysis.dta", replace
